<template>
	<view class="content" :style="theme">
		<!-- #ifdef MP-WEIXIN -->
		<u-navbar :placeholder="false" :bgColor="bgColor">
			<view slot="left" class="nav_title" @click="navBack">
				<u-icon name="arrow-left" color="#fff" /><text style="z-index: 10;color: #fff">积分商城</text>
			</view>
		</u-navbar>
	    <!-- #endif -->
		<view class="nav" :style="{backgroundImage: 'url(' + ossHost + '/public/model/jifen_bg.png)'}">
			<view class="nav-foot">
				<view class="flex dqmx">
					<text>当前积分</text><text class="mx" @click="jump('/pages/integral/record')">积分明细</text>
				</view>
				<view class="jfnum">{{integral || 0}}</view>
				<view class="tip flex-cb">
					<view v-if="destroyDate">
						<image :src="imgHost+'/jifen_ic_tixing.png'"></image>积分将于<text>{{destroyDate}}</text>清空，请合理使用
					</view>
					<!-- <view>积分规则<image :src="imgHost+'/jifen_ic_more.png'"></image></view> -->
				</view>
			</view>
		</view>
		<view class="card">
			<view class="bt">
				热兑推荐
				<view class="right" @click="jump2('/pages/integral/order')">
					我的兑换
					<image :src="imgHost+'/xic_duihuan.png'"></image>
				</view>
			</view>
			<view class="flex-c">
				<view class="card_box" v-for="(item, index) in list" :key="index"
					@click="jump2('/pages/integral/detail?id=',item.id+'&type='+item.type)">
					<image :src="item.type=='1'?item.img_url:ossHost+'/member/20200412/hb1.png'"></image>
					<view class="wptitle">{{item.name}}</view>
					<view class="wpjf"><text>{{item.price}}</text>积分</view>
					<view v-if="item.stock || item.stock === 0" class="mpkc">库存：{{item.stock || 0}}</view>
				</view>
			</view>
			<u-loadmore v-if="end && list.length >= 10" :status="status" line />
			<view v-if="list.length === 0" class="no-order" style="min-height: 40vh;">
				<image :src="imgHost+'/default_nodata.png'"></image>
				<view>暂无数据～</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [],
				page: 1,
				status: 'nomore',
				noClick: true,
				end: false,
				firstQueryTime: '',
				integral: '',
				destroyDate: '',
				bgColor: 'rgba(221,91,64,0)'
			}
		},
		onShow() {
			this.reset()
		},
		methods: {
			jump(url, params, a) {
				this.$app.jump(url, params, a);
			},
			jump2(url, params, a) {
				this.$app.jump2(url, params, a);
			},
			reset() {
				this.list = [];
				this.page = 1;
				this.firstQueryTime = this.$app.firstQueryTime()
				this.end = false;
				this.getList()
			},
			navBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			getList() {
				this.$app.ajax({
					api: this.$api.goodsList(),
					data: {
						pagination: {
							page: this.page,
							firstQueryTime: this.firstQueryTime,
							rows: 10
						},
						param: {
							memberId: this.userInfo.id,
							venueId: this.venueId
						}
					}
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.integral = res.record.integral
						this.destroyDate = res.record.destroyDate
						if (!res.record.goodsList || res.record.goodsList.length < 10) {
							this.end = true
						}
						if (res.record.goodsList) {
							this.list = this.list.concat(res.record.goodsList)
						}
					}
				}).catch(() => {})
			},
			reachBottom() {
				if (!this.end) {
					this.page += 1;
					this.getList();
				}
			},
			// 触底加载更多数据
			onReachBottom(e) {
				this.reachBottom()
			},
			onPageScroll(res) {
				let topOpacity = res.scrollTop / 100 - .4
				if (res.scrollTop < 40) {
					topOpacity = 0
				} else if (topOpacity >= 1) {
					topOpacity = 1
				}
				this.bgColor = `rgba(221,91,64,${topOpacity})`
			},

		}

	}
</script>
<style>
	page {
		background-color: #fff;
	}
</style>
<style scoped lang="scss">
	.content {
		background: #fff;
		position: relative;
	}

	.nav {
		width: 750rpx;
		height: 468rpx;
		z-index: 1;
		position: relative;
		background-color: #ffffff;
		background-repeat: no-repeat;
		background-position: bottom center;
		background-size: cover;
	}
	.dqmx {
		font-size: 26rpx;
		line-height: 1;
		font-weight: 400;
		padding-left: 30rpx;
		justify-content: space-between;
		color: #FFFFFF;
	}

	.mx {
		color: $red;
		font-size: 24rpx;
		width: 140rpx;
		line-height: 52rpx;
		text-align: center;
		background: #FFFFFF;
		border-radius: 36rpx 0rpx 0rpx 36rpx;
	}

	.jfnum {
		font-size: 72rpx;
		line-height: 1;
		margin: 20rpx 30rpx 30rpx;
		color: #fff;
		font-family: Arial-BoldMT, Arial;
		font-weight: normal;
	}

	.tip {
		box-sizing: border-box;
		padding: 0 30rpx;
		color: #FFFFFF;
		font-size: 24rpx;
		line-height: 1.5;
	}

	.tip text {
		color: rgba(255, 232, 90, 1);
	}

	.tip view:first-of-type image {
		width: 30rpx;
		height: 30rpx;
		margin-right: 16rpx;
		vertical-align: middle;
	}

	.tip view:last-of-type image {
		width: 26rpx;
		height: 26rpx;
		margin-left: 10rpx;
		vertical-align: middle;
	}

	.nav-foot {
		position: absolute;
		width: 100%;
		bottom: 70rpx;
		left: 0;
	}

	.nav view {
		z-index: 10;
	}

	.card {
		width: 100%;
		position: absolute;
		width: 100%;
		left: 0;
		top: 448rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 0 0;
		box-sizing: border-box;
		padding: 40rpx 30rpx;
		z-index: 10;
	}

	.bt {
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		line-height: 1.5;
		color: #222222;
		margin-bottom: 40rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.right {
			font-size: 14px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #333333;
			image {
				width: 28rpx;
				height: 28rpx;
				margin-left: 8rpx;
				vertical-align: middle;
			}
		}
	}

	.card .flex-c {
		flex-wrap: wrap;
	}

	.card_box {
		width: 332rpx;
		line-height: 1.5;
		margin-bottom: 30rpx;
	}

	.card_box:nth-of-type(odd) {
		margin-right: 26rpx;
	}

	.card_box image {
		width: 332rpx;
		height: 332rpx;
		border-radius: 8rpx;
	}

	.wptitle {
		font-size: 30rpx;
		color: #222222;
		/* white-space: nowrap;
	  text-overflow: ellipsis;
	  -webkit-text-overflow: ellipsis;
	  overflow: hidden; */
		margin: 10rpx 0;
	}

	.wpjf {
		color: #333333;
		font-size: 22rpx;
		line-height: 40rpx;
	}

	.wpjf text {
		font-size: 36rpx;
		font-weight: 600;
		color: $red;
		margin-right: 10rpx;
	}

	.mpkc {
		color: #999999;
		font-size: 22rpx;
		margin-top: 10rpx;
	}
</style>